package com.jyb.qiyefuwu.view.adpater;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.jyb.qiyefuwu.BR;
import com.jyb.qiyefuwu.R;
import com.jyb.qiyefuwu.entity.DatabaseListEntiy;
import com.jyb.qiyefuwu.view.activity.usercenter.SalesOrderDetailsActivity;
import com.swgk.core.helper.OnMultiClickListener;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;


public class DatabaseInfoAdapter extends BaseRecycleAdapter<DatabaseListEntiy> {

    private ImageView imgPdf;
    private ImageView imgIcn;
    private ImageView imgDelete;
    public IDelete iDelete;
    private boolean isGone;


    public DatabaseInfoAdapter(Context context, List<DatabaseListEntiy> datas, boolean isGone) {
        super(context, R.layout.item_database, datas);
        this.isGone = isGone;
    }

    @Override
    public void convert(ItemViewHolder holder, final DatabaseListEntiy entity) {
        holder.setBinding(BR.viewModel, entity);
        imgPdf = holder.itemView.findViewById(R.id.img_pdf);
        imgIcn = holder.itemView.findViewById(R.id.img_icn);
        imgDelete = holder.itemView.findViewById(R.id.img_delete);
        if (isGone) {
            imgDelete.setVisibility(View.GONE);
        }
        if (!entity.getFileUrl().contains(".pdf")) {
            imgIcn.setVisibility(View.VISIBLE);
            Glide.with(context)
                    .load(entity.getFileUrl())
                    .error(R.mipmap.image_order_list_defuntimage)
                    .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(2)))
                    .into(imgIcn);//图标
        } else {
            imgIcn.setVisibility(View.GONE);
        }
        imgDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iDelete.delete(entity.getId());
            }
        });

        imgPdf.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转pdf
                iDelete.lookPdf(entity.getFileUrl());
            }
        });

        imgIcn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //查看图片
                iDelete.lookImg(entity.getFileUrl());
            }
        });
    }

    public interface IDelete {
        void delete(String id);

        void lookPdf(String path);

        void lookImg(String path);
    }

    public void onDelete(IDelete iDelete) {
        this.iDelete = iDelete;
    }
}
